import {Injectable} from "@angular/core";
import {MaterialBill} from "./domains";
import {HttpHelper} from "./HttpHelper"
import {HttpResponse} from "@angular/common/http";

@Injectable()
export class MaterialBillServices {
    materialBillUrl:string="material-bill";
    constructor(private httpHelper:HttpHelper){

    }
    getMaterialBills(page,size):Promise<MaterialBill[]>{
        let url = this.materialBillUrl+`/?page=${page}&size=${size}`;
        return this.httpHelper.getJson<MaterialBill[]>(url)
    }
    addMaterialBill(processId:number,bill:MaterialBill):Promise<MaterialBill>{
        let url = this.materialBillUrl+`/?process=${processId}`;
        return this.httpHelper.postToJson(url,bill);
    }
    addMateralLiable(bill):Promise<MaterialBill> {
        let url = this.materialBillUrl+`/check/?bill=${bill}`;
        return this.httpHelper.putToJson<MaterialBill>(url,null);
    }
    getMaterialBill(billId):Promise<MaterialBill>{
        let url = this.materialBillUrl+`/`+billId;
        return this.httpHelper.getJson<MaterialBill>(url);
    }
}